package com.github.m6d21.sso.business.controller.test;

import com.github.m6d21.sso.common.util.AesUtil;
import com.github.m6d21.sso.core.annotation.Login;
import com.github.m6d21.sso.support.model.Response;
import com.github.m6d21.sso.support.util.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.HashMap;
import java.util.Map;
import javax.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2018-12-07 Fri 13:27:18
 * @since 1.0.0
 */
@Api(value = "test-aes", description = "aes加密测试")
@Validated
@RestController
@RequestMapping("/test/aes")
public class AesController {

    @ApiOperation(value = "加密测试", httpMethod = "GET")
    @GetMapping("/encrypt")
    @ResponseBody
    @Login(cookieExpire = 3600)
    public Response<Map<String, String>> encrypt
        (@NotNull(message = "明文不能为空") @RequestParam("content") String content) {
        Map<String, String> data = new HashMap<>();
        data.put(content, AesUtil.encrypt(content));
        return ResponseUtil.success(data);
    }

    @ApiOperation(value = "解密测试", httpMethod = "GET")
    @GetMapping("/decrypt")
    @ResponseBody
    public Response<Map<String, String>> decrypt
        (@NotNull(message = "密文不能为空") @RequestParam("content") String content) {
        Map<String, String> data = new HashMap<String, String>();
        data.put(content, AesUtil.decrypt(content));
        return ResponseUtil.success(data);
    }
}
